/**
 * Created by Freeman on 2016/7/7.
 */
"use strict";
import {CLEAR_SEARCH,REQUEST_SEARCH,REQUEST_SEARCH_SUCCESS,REQUEST_SEARCH_FAILURE,ADD_SEARCH_SUCCESS,CHANGE_SEARCH} from '../types'
const state = {
    option:{
        pageNo:1,
        pageSize:10,
        q:'',

    },
    items:[],
    isFetching:false,
    isMore : false
}
const mutations = {
    [CLEAR_SEARCH](state){
        state.option = {
            pageNo:1,
            pageSize:10,
            q:''
        }
        state.isFetching = false
        state.items = []
        state.isMore = false
    },
    [CHANGE_SEARCH](state,data){
        state.option = {...state.option,...data}
    },
    [REQUEST_SEARCH](state){
        state.isFetching = true
    },
    [REQUEST_SEARCH_SUCCESS](state,action){
        state.isFetching = false
        state.items = action.hits
        state.isMore = action.isMore
    },
    [REQUEST_SEARCH_FAILURE](state){
        state.isFetching = false
    },
    [ADD_SEARCH_SUCCESS](state,action){
        state.isFetching = false
        state.items = [...state.items,...action.hits]
        state.isMore = action.isMore
    }
}

export default {
    state,
    mutations
}